<main class="lyear-layout-content">

    <div class="container-fluid p-t-15">

        <div class="row">
            <div class="col-lg-6">
                <div class="card">
                    <div class="card-header">
                        <h4>性别</h4>
                    </div>
                    <div class="card-body">
                        <canvas id="chart-pie" width="280" height="280"></canvas>
                    </div>
                </div>
            </div>
            <div class="col-lg-6">
                <div class="card">
                    <div class="card-header">
                        <h4>认证状态</h4>
                    </div>
                    <div class="card-body">
                        <canvas id="chart-doughnut" width="280" height="280"></canvas>
                    </div>
                </div>
            </div>
        </div>

    </div>

</main>

<script type="text/javascript" src="/static/admin/js/Chart.min.js"></script>

<script>
    $.ajax({
        type: "post",
        url: `{:url('admin/analysis/user')}`,
        data: {
            action:'pie'
        },
        dataType: "json",
        success: function (res) {
            if(res.code === 1)
            {
                var sex = res.data.sex
                var auth = res.data.auth

                new Chart($("#chart-pie"), {
                    type: 'pie',
                    data: {
                        labels: ["男", "女", "保密"],
                        datasets: [{
                            data: sex,
                            backgroundColor: ['rgba(255,99,132,1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)']
                        }]
                    },
                    options: {
                        responsive: false
                    }
                });

                new Chart($("#chart-doughnut"),{
                    type: 'pie',
                    data: {
                        labels: ["已认证", "未认证"],
                        datasets: [{
                            data: auth,
                            backgroundColor: ['rgba(255,99,132,1)', 'rgba(54, 162, 235, 1)']
                        }]
                    },
                    options: {
                        responsive: false
                    }
                })
            }
        }
    });
</script>